package com.xbb.service;

import com.xbb.bean.FileBean;
import org.springframework.stereotype.Service;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by xbb on 15/8/21.
 */
@Service
public class ImproveAService {

    private String PATH = "/Users/xbb/pan";

    /**
     * 获取目录下的文件
     */
    public List<FileBean> getFiles(String path){
        path = PATH + "/" + path;
        File file = new File(path);
        File[] files = file.listFiles();
        List<FileBean> list = new ArrayList<FileBean>();
        for(File file1 : files){
            FileBean fileBean = new FileBean();
            fileBean.setName(file1.getName());
            fileBean.setSize(file1.length());
            Long time = file1.lastModified();
            String times = new SimpleDateFormat("yyyy-MM-dd").format(new Date(time));
            fileBean.setTime(times);
            fileBean.setIsDir(file1.isDirectory());
            list.add(fileBean);
        }
        return list;
    }

}

